import { getFlowResultSummary } from '@/api';
// import { MciButton, MciDialog, MciInput, MciNotification, MciSvgIcon } from '@/components/base';
// import { ElCascader } from 'element-plus';
import { SumItem } from './SumItem';

export const DecisionSum = defineComponent({
  props: {
    flowId: {
      type: String,
      default: null
    }
  },
  emits: ['refreshList'],
  setup(props) {
    const sumVals = ref([]);

    const initData = async (flowId: string) => {
      let data = await getFlowResultSummary({ flowIds:flowId });
      if(data) {
        const result = Object.keys(data).map(key => {
          let title = '';
          switch(key) {
            case 'total':
              title = '总进件数';
              break;
            case 'pass':
              title = '总通过数';
              break;
            case 'reject':
              title = '总拒绝数';
              break;
            case 'manual':
              title = '总人工审核数';
              break;
            default:
              break;
          }
          return {
              title: title,
              value: data[key]
            };
          }
        );
        sumVals.value = result;
      }
    };

    watch(
      () => props.flowId,
      (newFlowId) => {
        if (newFlowId) {
          initData(newFlowId);
        }
      },
      { immediate: true, deep: true }
    );

    return () => (
      <div class="w-full flex justify-between mt-16 gap-16">
        {sumVals.value.map((item: any) => (
          <SumItem value={item.value} title={item.title} class="bg-fill-2 grow" color={item.title === '总拒绝数'? '#E34D59':''} />
        ))}
      </div>
    );
  }
});
